package com.ruoyi.web.controller.market.member;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.MemberLoginsession;
import com.ruoyi.member.service.IMemberLoginsessionService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.MemberLoginsessionWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 登陆信息Controller
 * 
 * @author ruoyi
 * @date 2022-08-02
 */
@Controller
@RequestMapping("/member/loginsession")
public class MemberLoginsessionController extends BaseController
{
    private String prefix = "member/loginsession";

    @Autowired
    private IMemberLoginsessionService memberLoginsessionService;

    @RequiresPermissions("member:loginsession:view")
    @GetMapping()
    public String loginsession()
    {
        return prefix + "/loginsession";
    }

    /**
     * 查询登陆信息列表
     */
    @RequiresPermissions("member:loginsession:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MemberLoginsession memberLoginsession)
    {
        startPage();
        List<Map<String, Object>> mapList = memberLoginsessionService.selectMemberLoginsessionListMap(memberLoginsession);
        mapList = new MemberLoginsessionWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出登陆信息列表
     */
    @RequiresPermissions("member:loginsession:export")
    @Log(title = "登陆信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MemberLoginsession memberLoginsession)
    {
        List<MemberLoginsession> list = memberLoginsessionService.selectMemberLoginsessionList(memberLoginsession);
        ExcelUtil<MemberLoginsession> util = new ExcelUtil<MemberLoginsession>(MemberLoginsession.class);
        return util.exportExcel(list, "登陆信息数据");
    }

    /**
     * 新增登陆信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存登陆信息
     */
    @RequiresPermissions("member:loginsession:add")
    @Log(title = "登陆信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MemberLoginsession memberLoginsession)
    {
        return toAjax(memberLoginsessionService.insertMemberLoginsession(memberLoginsession));
    }

    /**
     * 修改登陆信息
     */
    @RequiresPermissions("member:loginsession:edit")
    @GetMapping("/edit/{token}")
    public String edit(@PathVariable("token") String token, ModelMap mmap)
    {
        MemberLoginsession memberLoginsession = memberLoginsessionService.selectMemberLoginsessionByToken(token);
        mmap.put("memberLoginsession", memberLoginsession);
        return prefix + "/edit";
    }

    /**
     * 修改保存登陆信息
     */
    @RequiresPermissions("member:loginsession:edit")
    @Log(title = "登陆信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MemberLoginsession memberLoginsession)
    {
        return toAjax(memberLoginsessionService.updateMemberLoginsession(memberLoginsession));
    }

    /**
     * 删除登陆信息
     */
    @RequiresPermissions("member:loginsession:remove")
    @Log(title = "登陆信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(memberLoginsessionService.deleteMemberLoginsessionByTokens(ids));
    }
}
